﻿using Microsoft.AspNetCore.SignalR.Client;
using System;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace winform
{
    public partial class FrmSignalrClient : Form
    {
        public FrmSignalrClient()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Task.Factory.StartNew(() =>//开启新线程执行Signalr初始化
            {
                SignalrClient.Instance.On<string>("ReceiveMessage", message =>
                {
                    this.txtRecivedMsg.BeginInvoke(new Action(() =>
                    {
                        this.txtRecivedMsg.Text += message + "\r\n";
                    }));
                });
                SignalrClient.Instance.StartAsync().Wait();
            });
        }

        private void btnSendMsg_Click(object sender, EventArgs e)
        {
            SignalrClient.Instance.SendAsync("SendMessageAll", txtmsg.Text);
        }
    }
}
